﻿using System.Globalization;
using System.Windows.Data;

namespace Super.Hmi.Converters
{
    /// <summary>
    /// 将集合中的前N个元素转换为新的集合
    /// </summary>
    public class TakeItemsConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is IEnumerable<object> items && int.TryParse(parameter?.ToString(), out int takeCount))
            {
                return items.Take(takeCount);
            }
            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
